package com.agh.portal.service;

import java.util.HashSet;
import java.util.Set;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.agh.portal.domain.Course;
import com.agh.portal.domain.CourseStudent;
import com.agh.portal.domain.Student;

@Service
@Transactional
public class StudentService {
	
	public Set<Course> getCoursesByStudent(Student student){
		Set<CourseStudent> courseStudents = student.getCourses();
		Set<Course> courses = new HashSet<Course>();
		for(CourseStudent courseStudent : courseStudents){
			courses.add(courseStudent.getCourse());
		}
		return courses;
	}

	public Student createStudent(String name, String surname, String emailAddress) {
		Student student = new Student();
		student.setName(name);
		student.setSurname(surname);
		student.setEmail(emailAddress);
		student.setAvatarId("avatar-blank-128.jpg");
		student.persist();
		return student;
	}
	
	
}
